﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using TestManagerClient.Model;

namespace TestManagerClient.Pages
{
    /// <summary>
    /// Interaction logic for EditQuestion1.xaml
    /// </summary>
    public partial class EditQuestion1 : Page
    {
        List<String> categoryList = new List<String>();
        public Questions _Question { get; set; }


        public EditQuestion1()
        {
            InitializeComponent();

            categoryList.Add("Kategoria 1");
            categoryList.Add("Kategoria 2");

            lst_CategoryList.ItemsSource = categoryList;

            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
            InformationDisplay.HideError(errorGrid, errorTextBlock);

        }

        public EditQuestion1(Questions _question)
        {
            InitializeComponent();

            categoryList.Add("Kategoria 1");
            categoryList.Add("Kategoria 2");

            lst_CategoryList.ItemsSource = categoryList;

            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
            InformationDisplay.HideError(errorGrid, errorTextBlock);

            if (_question != null)
            {
                txt_QuestionName.Text = _question.Name;
                txt_QuestionDescription.Text = _question.Description;
                lst_CategoryList.SelectedItem = _question.Category;
                _Question = _question;

            }

        }

        #region Metody obsługujące przyciski zamknięcia informacji

        private void closeNotificationGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
        }

        private void closeWarningGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
        }

        private void closeErrorGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideError(errorGrid, errorTextBlock);
        }

        #endregion

        private void btn_SaveQuestions_Click(object sender, RoutedEventArgs e)
        {
            if (txt_QuestionName.Text != "" && txt_QuestionDescription.Text != "")
            {
                if(_Question == null)
                {
                    Questions question = new Questions();
                    question.Name = txt_QuestionName.Text;
                    question.Description = txt_QuestionDescription.Text;
                    question.Category = lst_CategoryList.SelectedValue.ToString();

                    QuestionsPage.QuestionsList.Add(question);

                }
                else
                {
                    var _question = QuestionsPage.QuestionsList.Where(p => p.Name == _Question.Name).First();
                    _question.Name = txt_QuestionName.Text;
                    _question.Description = txt_QuestionDescription.Text;
                    _question.Category = lst_CategoryList.SelectedValue.ToString();
                }

                btn_SaveQuestions.Command = NavigationCommands.GoToPage;
                btn_SaveQuestions.CommandParameter = "Pages/QuestionsPage.xaml";
            }
        }

        private void btn_Close_Click(object sender, RoutedEventArgs e)
        {
             btn_Close.Command = NavigationCommands.GoToPage;
             btn_Close.CommandParameter = "Pages/QuestionsPage.xaml";
        }
    }
}
